> — greater than
' Add up numbers that the user enters.
' When the user enters any negative number,
' print the sum and end the program.
'
LET SUM = 0
'
PRINT "Enter a positive number"
INPUT NUMBER
'
DO WHILE NUMBER > 0
LET SUM = SUM + NUMBER
PRINT "Enter a positive number."
INPUT NUMBER
LOOP
'
PRINT "The sum is", SUM
END
DO WHILE
loopsHere is an outline of the above program. The program will do "something or other" until a sentinel value is entered.
. . . . do beginning things . . . PRINT "Enter first number" INPUT NUMBER ' DO WHILE ... number is not a sentinel value ... . . . do something or other . . . PRINT "Enter the next number." INPUT NUMBER LOOP . . . . do ending things . . . . END
To change this scheme into a program you have to decide what you want to do, and decide how to fill in the blanks in this scheme to do it. Sometimes a blank needs to be filled with many statements; sometimes with none.
You want a program that repeatedly computes the square root of numbers the user types in. In QBasic SQR ( NUMBER ) is the square root of NUMBER. Since negative numbers don't have square roots, you want any negative number to act as a sentinel. You expect the monitor screen to look something like:
Enter the first number ? 3 Square root is: 1.7320508 Enter the next number ? 4 Square root is: 2 Enter the next number ? -10 Bye
Look at the scheme DO WHILE
programs.
To start out,
decide what to do with the blanks:
. . . . do beginning things . . .and
. . . . do ending things . . . .
The remaining blanks will be left until later.